﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace APP
{
    public class FileHelper
    {
        public static void DownloadWebFile(string webFileUrl, string fileName, string parentPath)
        {
            if (!Directory.Exists(parentPath))
                Directory.CreateDirectory(parentPath);
            var myWebClient = new WebClient();
            myWebClient.Credentials = CredentialCache.DefaultCredentials;
            var inStream = myWebClient.OpenRead(new Uri(webFileUrl));
            var fileFullPath = parentPath + fileName;

            var fs = new FileStream(fileFullPath, FileMode.OpenOrCreate, FileAccess.Write);
            var by = new byte[10240];
            int c = 0;
            while ((c = inStream.Read(by, 0, 10240)) > 0)
            {
                fs.Write(by, 0, c);
            }
            fs.Close();
        }
    }
}
